package com.heo.redis.impl;

import java.io.Serializable;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.heo.pub.ServerConfig;
import com.heo.redis.*;
import com.heo.task.CallBackTaskQueue;
import com.heo.task.thread.CallBackInfo;
import com.heo.util.NettyChannelMapUtils;

public class MyExpiredMessageDelegateImpl implements MyExpiredMessageDelegate {

	@Override
	public void handleMessage(String message) {
		System.out.println("String = " + message);
	}

	@Override
	public void handleMessage(Map message) {
		System.out.println("Map = " + message);
	}

	@Override
	public void handleMessage(byte[] message) {
		System.out.println("byte = " + message);
	}

	@Override
	public void handleMessage(Serializable message) {
		String mess = message.toString();
		if(mess.startsWith(NettyChannelMapUtils.DEVICE_CONTROL)) {
			String imei = mess.substring(mess.lastIndexOf(":") + 1);
			JSONObject sendJson = new JSONObject();
			sendJson.put("imei", imei);
			CallBackInfo callBackInfo = new CallBackInfo(sendJson.toString(), ServerConfig.SUB_HTTPS_URL + "/deviceApi/updateRequestDate.do?imei=" + imei);
			callBackInfo.setMaxReSendCount(1);
			callBackInfo.setExpireTime(100);
			CallBackTaskQueue.getInstance().addCallBackMsg(callBackInfo);
		};
	}

	@Override
	public void handleMessage(Serializable message, String channel) {
		System.out.println("Serializable = " + message + ",channel=" + channel);
	}
}
